package com.sky.controller.user;

import com.sky.entity.AddressBook;
import com.sky.result.Result;
import com.sky.service.AddressBookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/addressBook")
@Api(tags = "地址簿接口")
public class AddressBookController {

    @Autowired
    private AddressBookService addressBookService;

    @GetMapping("/list")
    @ApiOperation("查询当前登录用户的所有地址信息")
    public Result addressBookList(){
        return addressBookService.addressBookList();
    }

    @PostMapping
    @ApiOperation("新增地址")
    public Result saveAddressBook(@RequestBody AddressBook addressBook){
        return addressBookService.saveAddressBook(addressBook);
    }

    @DeleteMapping
    @ApiOperation("根据id删除地址")
    public Result deleteAddressBookById(String id){
        return addressBookService.deleteAddressBookById(id);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询地址")
    public Result getAddressBookById(@PathVariable String id){
        return addressBookService.getAddressBookById(id);
    }

    @PutMapping
    @ApiOperation("根据id修改地址")
    public Result updateAddressBookById(@RequestBody AddressBook addressBook){
        return addressBookService.updateAddressBookById(addressBook);
    }

    @PutMapping("/default")
    @ApiOperation("设置默认地址")
    public Result setDefaultAddressBook(@RequestBody AddressBook addressBook){
        return addressBookService.setDefaultAddressBook(addressBook);
    }

    @GetMapping("/default")
    @ApiOperation("查询默认地址")
    public Result getDefaultAddressBook(){
        return addressBookService.getDefaultAddressBook();
    }

}
